<template>
	<view>
		<u-navbar :title="$t('launchDetail.navText')" placeholder :autoBack="true" />
		<view v-if="!loading">
			<view class="popup">
				<view class="money">{{detail.price}}元</view>
				<view class="condition">满{{detail.limit}}元可用</view>
			</view>
			<view class="content">
				<view class="title">
					<view class="flex">
						<image src="/static/image/merchant_14.png"></image>
						<view>{{$t('launchDetail.title_1')}}</view>
					</view>
					<view>满{{detail.limit}}元可用</view>
				</view>
				<view class="title">
					<view class="flex">
						<image src="/static/image/merchant_15.png"></image>
						<view>{{$t('launchDetail.title_2')}}</view>
					</view>
					<view>{{detail.startdate}}至{{detail.enddate}}</view>
				</view>
				<view class="title">
					<view class="flex">
						<image src="/static/image/merchant_16.png"></image>
						<view>{{$t('launchDetail.title_3')}}</view>
					</view>
					<view>{{getStatus(detail.state)}}</view>
				</view>
				<view class="title">
					<view class="flex">
						<image src="/static/image/merchant_12.png"></image>
						<view>{{$t('launchDetail.title_4')}}</view>
					</view>
					<view>{{detail.alreadygrant}}张</view>
				</view>
				<view class="title">
					<view class="flex">
						<image src="/static/image/merchant_17.png"></image>
						<view>{{$t('launchDetail.title_5')}}</view>
					</view>
					<view>{{detail.usenum}}张</view>
				</view>
				<u-button v-if="detail.state == '1'" @click="blockUp" :text="$t('launchDetail.submitBtn')"
					shape="circle" :customStyle="btnStyle"></u-button>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				btnStyle: {
					background: "rgba(255, 193, 2, 1)",
					color: "#fff",
					border: "none",
					height: "50px",
					margin: "50px auto 0px"
				},
				loading: true,
				detail: {}
			};
		},
		onLoad(event) {
			this.id = event.id
			this.getDetail()
		},
		methods: {
			getStatus(state) {
				switch (parseInt(state)) {
					case 1:
						return '发行中'
						break;
					case 2:
						return '已停用'
						break;
					case 3:
						return '已失效'
						break;
				}
			},
			getDetail() {
				this.$http.post('wanlshop/coupon/couponDetail', {
					coupon_id: this.id
				}).then(res => {
					if (res.code == 1) {
						this.detail = res.data.coupon
						this.loading = false
					}
				})
			},
			blockUp() {
				uni.showLoading({
					title: "停用中...",
					mask: true
				})
				this.$http.post('wanlshop/coupon/couponStop', {
					coupon_id: this.id
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						setTimeout(() => {
							this.$refs.uToast.show({
								type: 'default',
								message: "停用成功",
								duration: 1000,
								complete() {
									uni.$emit("updatePopup")
									uni.navigateBack()
								}
							})
						}, 150)
					}
				})
			}
		}
	}
</script>
<style>
	page {
		background: #fff;
	}
</style>
<style lang="scss" scoped>
	.content {
		padding: 0rpx 46rpx;

		.title {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 38rpx;
			border-bottom: 2rpx solid rgba(242, 242, 242, 1);
			margin-bottom: 20rpx;
			color: #000;
			font-size: 32rpx;
		}

		.flex {
			display: flex;
			align-items: center;

			image {
				width: 40rpx;
				height: 40rpx;
				margin-right: 20rpx;

			}
		}
	}

	.popup {
		width: 520rpx;
		height: 216rpx;
		margin: 74rpx auto 88rpx;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		background-image: url();
		padding: 50rpx;
		text-align: center;
		box-sizing: border-box;

		.money {
			color: #fff;
			font-size: 40rpx;
			font-weight: bold;
			text-align: center;
			margin-bottom: 20rpx;
		}

		.condition {
			color: #fff;
			font-size: 28rpx;
			text-align: center;
		}
	}
</style>
